﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using UI.ParentForm;
using Components;
using UI.Lib;
using Controls;
using System.Collections;
using UI.Lib.Factory;

namespace UI.Charts
{
    public partial class SellOrderChart : BasePivot
    {
        public SellOrderChart(string modulename, string action)
            : base(modulename, action)
        {
            InitializeComponent();

            expSearchBox.Height = 95;
        }

        public override bool BeforePopWin(string name, ref string where, ref string[] others)
        {
            if ("sellercode" == name)
            {
                where = string.Format(" status ='1' {0} ", Context.GetAppKeyWhere("usercode", true));
            }
            else if ("shopcode" == name)//门店
            {
                string sellerid = Validation.ToString(this.tbSummary.GetValue("sellid"));
                if (string.IsNullOrEmpty(sellerid))
                {
                    MessageBox.Show("请先选择销售商！", "提示");
                    this.tbSummary.Focus("sellercode");
                    return false;
                }

                where = string.Format("slistid = '{0}' {1} ", sellerid, Context.GetAppKeyWhere("muser", true));
            }

            return true;
        }

        public override void AfterPopWin(string name, System.Collections.Hashtable data, bool ischange)
        {
            if (ischange)
            {
                if ("sellercode" == name)
                {
                    this.tbSummary.SetValue("shopid", "");
                    this.tbSummary.SetValue("shopcode", "");
                    this.tbSummary.SetValue("shopname", "");
                }
            }
        }


        protected override void DoSearch()
        {
            Hashtable where = new Hashtable();
            where["sellerid"] = tbSummary.GetValue("sellid");
            where["shopid"] = tbSummary.GetValue("shopid");
            where["status"] = tbSummary.GetValue("status");
            where["start"] = Validation.ToDate(tbSummary.GetValue("startdate"), Global.MinDate);
            where["end"] = Validation.ToDate(tbSummary.GetValue("enddate"), Global.MaxDate);

            DataTable dt = CommonHelper.Entity.ExecFun("getorderchartdatasource", where);
            where = null;

            BindGrid(dt);
        }
    }
}
